<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>我有几句话藏在月亮里想对你说</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <link rel="stylesheet" href="share.css">
</head>

<body>
    <div style="display:none"><img src="images/sharedimg.jpg" alt="" /></div>

    <div id="bgmimg">

    </div>


    <script>
        var sharedurl = " <%-  shareUrl  %>  ";


        var configurl = window.location.href;
        var wechatconfig = `http://www.id-bear.com/node/moon/share/wechatconfig?xxconfigurl=${configurl}`;

        axios
            .get(wechatconfig)
            .then(function (response) {
                wxglobleconfig = response.data;
                //获取微信配置
                console.log('微信配置', wxglobleconfig);

                // 微信配置
                wx.config(wxglobleconfig);

                wx.ready(function () {
                    wx.hideMenuItems({
                        menuList: [
                            "menuItem:share:qq",
                            "menuItem:share:weiboApp",
                            "menuItem:favorite",
                            "menuItem:share:facebook",
                            "menuItem:share:QZone",
                            "menuItem:openWithSafari",
                            "menuItem:share:brand"
                        ], // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
                        success: function (res) {
                            //alert("隐藏");
                        }
                    });

                    wx.showMenuItems({
                        menuList: ["onMenuShareAppMessage", "onMenuShareTimeline"] // 要显示的菜单项，所有menu项见附录3
                    });

                    var initWxShareTimeObj = {
                        title: "我有几句话藏在月亮里想对你说", // 分享标题
                        link: sharedurl, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: "http://www.id-bear.com/node/moon/images/sharedimg.jpg", // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                            alert('您取消了分享');
                        }
                    };

                    var initWxShareAppMessage = {
                        title: "我有几句话藏在月亮里想对你说", // 分享标题
                        desc: "明月寄相思 天涯共此时 ", // 分享描述
                        link: sharedurl, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: "http://www.id-bear.com/node/moon/images/sharedimg.jpg", // 分享图标
                        type: "link", // 分享类型,music、video或link，不填默认为link
                        dataUrl: "", // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () {
                            // 用户确认分享后执行的回调函
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                            alert('您取消了分享' + url);
                        }

                    };

                    setTimeout(function () {
                       // 分享到朋友圈
                        wx.onMenuShareTimeline(initWxShareTimeObj);
                        // 分享给朋友
                        wx.onMenuShareAppMessage(initWxShareAppMessage);

                    }, 2000);


                    wx.error(function (res) {
                        console.log("错误", res);
                    });
                })
            })
            .catch(function (error) {
                console.log("获取配置出错");
            });
    </script>

</body>

</html>